home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / srtsltn / data1.cab / Target / Samples / UserKey / userkey.c next >
Encoding:
C/C++ Source or Header  |  1998-08-05  |  2.1 KB  |  71 lines

  1. /****************************************************************************
  2.                     USERKEY.C
  3.           Author:   Mario Westphal
  4.                     Copyright ⌐ 1997,98 Mario M. Westphal
  5.             Date:   Tuesday, July 01, 1997
  6.                     Revised Sunday, April 06, 1998
  7.  
  8.  
  9.   This DLL serves as a sample for a user-defined Key DLL..
  10.  
  11. *****************************************************************************/
  12.  
  13. // Include the required definitions from the Sort Solution interface 
  14. #include "..\..\Include\sortsoli.h"
  15.  
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // This function gets called when Sort Solution needs to compare two keys
  19. // pKey1 points to the first key and KeyLen1 is the length in byte of the
  20. // memory area pointed to by pKey1.
  21. // pKey2 points to the second key and KeyLen2 is the length in byte of the
  22. // memory area pointed to by pKey2.
  23. // pData points to a string, containing whatever the user has used as the
  24. // "Data"-parameter in the definition of the User key.
  25. // If the user has omitted the "Data" parameter in the key definition, 
  26. // pData points to a zero length string
  27. // 
  28. // Returns:
  29. //    < 0        : pKey1 < pKey2
  30. //    > 0        : pKey1 > pKey2
  31. //    0     : pKey1 == pKey2
  32. //
  33. int WINAPI Compare(void* pKey1, unsigned KeyLen1, void* pKey2, unsigned KeyLen2, const char* pData)
  34. {
  35.     int res;
  36.  
  37.     res = memcmp(pKey1, pKey2, KeyLen1 > KeyLen2 ? KeyLen2 : KeyLen1);
  38.     if (res)
  39.         // If the keys are not equal, we're finished
  40.         return res;
  41.     else
  42.         // The smaller key wins!
  43.         return KeyLen1 - KeyLen2;
  44. }
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // 
  49. BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) {
  50.  
  51.     switch (fdwReason) {
  52.     case DLL_PROCESS_ATTACH:
  53.         // a process has attached: place all required initializations here
  54.         break;
  55.  
  56.     case DLL_THREAD_ATTACH:
  57.         // a thread has attached: place all required initializations here
  58.         break;
  59.  
  60.     case DLL_THREAD_DETACH:
  61.         // a thread has detached
  62.         break;
  63.  
  64.     case DLL_PROCESS_DETACH:
  65.         // a process has detached
  66.         break;
  67.    }
  68.  
  69.    return(TRUE);
  70. }
  71.